

#include <tenacitas_log/logger.h>

using namespace std;
using namespace tenacitas;


namespace tenacitas {
    namespace log {
        namespace test {

            /** A user class */

            template <typename t_logger>
            class a {
            public:

                a ( typename t_logger::ptr_t p_logger ) 
                : m_logger( p_logger ) {
                    //t_logger::level( t_logger::debug_level );                 
                }

                void m1( ) {
                    log_debug( m_logger ) << "logging something A" << ", and only that";
                }

                void m2( ) {

                    log_trace( m_logger ) << string( "trace debug" );

                    log_debug( m_logger ) << string( "log debug" );

                    log_warn( m_logger ) << "log warn";

                    log_info( m_logger ) << "log info";

                    log_error( m_logger ) << "log error";

                    log_critical( m_logger ) << "log critical";

                }
            private:
                typename t_logger::ptr_t m_logger;
            };

            //ofstream g_out;

            typedef logger<cout_printer> logger_test;

            /** Test 1 */
            void test1( logger_test::ptr_t l_logger );

            /** Test 2 */
            void test2( logger_test::ptr_t l_logger );

            /** Test 3 */
            void test3( logger_test::ptr_t l_logger );

            /** Test 4 */
            void test4( );
            
        }
    }
}

namespace ten_log_tst = tenacitas::log::test;


int main ( ) {
    
    ten_log_tst::logger_test::printer_ptr_t l_printer( new cout_printer( ) );
    ten_log_tst::logger_test::ptr_t l_logger( new ten_log_tst::logger_test( l_printer ) );

    ten_log_tst::test1( l_logger );
    ten_log_tst::test2( l_logger );
    ten_log_tst::test3( l_logger );
    ten_log_tst::test4( );

    char l_c;
    std::cin >> l_c;
}



using namespace tenacitas;

void
tenacitas::log::test::
test1( logger_test::ptr_t l_logger ) {
    
    log_debug( l_logger ) << "very simple log test";
}

void
tenacitas::log::test::
test2( logger_test::ptr_t l_logger ) {

    a<logger_test> l_a( l_logger );

    l_a.m1( );

}

void
tenacitas::log::test::
test3( logger_test::ptr_t l_logger ) {

    log_info( l_logger ) << "setting the log level to 'error_level'";

    //l_logger->level( logger_test::info_level );

    a<logger_test> l_a( l_logger );
    
    l_a.m2( );
}


void
tenacitas::log::test::
test4( ) {

//    logger<printer_test>::level( logger<printer_test>::trace_level );
    typedef logger<file_printer> file_logger;
    file_logger::printer_ptr_t l_printer( new file_logger::printer_t( "test4.log" ) );
    file_logger::ptr_t l_logger( new file_logger( l_printer, file_logger::trace_level ) );


    a<file_logger> l_a( l_logger );

    l_a.m1( );

}
